<?php include load_template('_subnav.php')?>
<h1>Editing Templates</h1>

<table border="0" cellspacing="5" cellpadding="5" width='100%' class='section' style='margin:5px 0;'>
    <tr>
        <td width='10%' id='page_template_list'>
            <h3 style='margin:2px;'>Templates</h3>
            <?php
            $selected_tplfile = str_replace('.php','', @$_GET['template_name'] );
            $selected_tplfile = strtr($selected_tplfile,'/\\','');
            echo "<ul>";
            foreach( $templates as $template_file_name => $template_human_name )
            {
                if ( $template_human_name != $template_file_name )
                {
                    echo '<li>'.link_to($template_human_name, 
                        array('controller'=>'admin/pages' ,'action'=>'templates?template_name='.rawurlencode($template_file_name))).
                    "<br>&nbsp;&nbsp;<span style='font-size:xx-small;color:#666'>$template_file_name</span></li>";
                } else {
                    echo '<li>'.link_to($template_file_name, 
                        array('controller'=>'admin/pages' ,'action'=>'templates?template_name='.rawurlencode($template_file_name))                        
                        ).'</li>';
                }
            }
            echo "</ul>";
            ?>
        </td>
        <td width='90%'>
            <?php
                if ( !empty($template_code) )
                {
            ?>
            <h3 style='margin:2px;'>Editing Template: <span style='color:red'><?php echo  htmlentities($template_name) ?></span></h3>

            <?php if($is_writable) echo form_tag('templates').hidden_field_tag('action','edit_template') ?>
            <?php echo  hidden_field_tag('template_name',htmlentities($template_name)) ?>
            <?php echo  text_area_tag('template_code',$template_code,array('size'=>'50x20','style'=>'width:100%')) ?>

            <?php
                if ( $is_writable )
                {
                    echo submit_tag('Edit Template').end_form_tag();
                } else {
                    echo "<p class='flash_error'>You could edit this template if it was writable by the server. Its located in: <b>/pixel/app/views/admin/pages/templates/$template_name</b></p>";
                }
            } else {
            ?>
            <?php echo  text_area_tag('template_code','Please select a template from the left to edit.',array('size'=>'50x20','style'=>'width:100%')) ?>
     
            <?php } ?>
        </td>
    </tr>
</table>





<div class='section'>
    <ul>
        <li><b>New Templates:</b> If you need to create new templates, you will need to have ftp access and will have to upload your new template into the /pixel/app/views/admin/pages/templates/ directory.</li>
        <li><b>Creating snippets:</b> If you need to create a template that will need to be included in your other templates, prefix the file name with an underscore. It will not be listed under the Pages template drop down menus for selecting templates. You can then include this template in your template with the following syntax: <br><code>&lt;?php include load_page_template('name_of_template.php'); ?&gt;</code></li>
        <li><b>Editable Regions</b>: You can create editable regions for templates that will allow you to enter content with a WYSIWYG editor. The syntax for creating an editable region is: <br><code>&lt;?php create_region($page['id'],'main_content',$admin_edit); ?&gt;</code></li>
    </ul>
</div>